//
//  ScheduleCalendarCell.m
//  MarryBackEnd
//
//  Created by mac on 2020/8/3.
//  Copyright © 2020 WPP. All rights reserved.
//

#import "ScheduleCalendarCell.h"
#import "ScheduleCalendarModel.h"
@interface ScheduleCalendarCell ()
@property(nonatomic,strong)UIView *bgView;
@property(nonatomic,strong)UILabel *toplab;
@property(nonatomic,strong)UILabel *bottomLab;
@property(nonatomic,strong)UIImageView *jiIV;
@property(nonatomic,strong)UIImageView *collectionIV;
@end
@implementation ScheduleCalendarCell
- (void)setCalendarModel:(ScheduleCalendarModel *)calendarModel
{
    _calendarModel = calendarModel;
    /**
     * 普通：topLab：rgba(34, 34, 34, 1) bottomLab:rgba(187, 187, 187, 1) bgView：rgba(255, 255, 255, 1)
     * 当天：未选中：topLab：rgba(34, 34, 34, 1) bottomLab:rgba(187, 187, 187, 1) bgView：rgba(245, 245, 245, 1)
     * 选中：topLab：rgba(255, 255, 255, 1) bottomLab:rgba(255, 255, 255, 1) bgView：rgba(255, 66, 66, 1)
     * 不在当月的： topLab：rgba(221, 221, 221, 1) bottomLab:rgba(221, 221, 221, 1) bgView：rgba(255, 255, 255, 1)
     * 
     */
    self.toplab.text = [NSString stringWithFormat:@"%ld",calendarModel.day];
    self.bottomLab.text = calendarModel.chineseName;
    self.bgView.backgroundColor = rgba(255, 255, 255, 1);
    if ([calendarModel.isChoice isEqualToString:@"1"]) {
        self.collectionIV.hidden = NO;
        self.jiIV.hidden = YES;
    } else {
        self.collectionIV.hidden = YES;
        if ([calendarModel.isLuck isEqualToString:@"1"]) {
            self.jiIV.hidden = NO;
        } else {
            self.jiIV.hidden = YES;
        }
    }
    switch (calendarModel.monthType) {
        case MonthTypeLast:
        {
            self.toplab.textColor = rgba(221, 221, 221, 1);
            self.bottomLab.textColor = rgba(221, 221, 221, 1);
        }
            break;
        case MonthTypeNext:
        {
            self.toplab.textColor = rgba(221, 221, 221, 1);
            self.bottomLab.textColor = rgba(221, 221, 221, 1);
        }
            break;
        case MonthTypeCurrent:
        {
            if (calendarModel.isSelected) {
                self.toplab.textColor = rgba(255, 255, 255, 1);
                self.bottomLab.textColor = rgba(255, 255, 255, 1);
                //self.bgView.backgroundColor = rgba(255, 66, 66, 1);
                self.bgView.backgroundColor = [UIColor ColorGradientType:ColorGradientTypeVertical andWithSize:self.bgView.size andWithColors:@[(__bridge id)rgba(255, 146, 92, 1).CGColor,(__bridge id)rgba(255, 66, 66, 1).CGColor]];
            } else {
                if (calendarModel.isToDay) {
                    self.toplab.textColor = rgba(34, 34, 34, 1);
                    self.bottomLab.textColor = rgba(187, 187, 187, 1);
                    self.bgView.backgroundColor = rgba(245, 245, 245, 1);
                } else {
                    self.toplab.textColor = rgba(34, 34, 34, 1);
                    self.bottomLab.textColor = rgba(187, 187, 187, 1);
                }
            }
        }
            break;
            
        default:
            break;
    }
}
#pragma mark - lazy懒加载
- (UIView *)bgView
{
    if (!_bgView) {
        UIView *view = [[UIView alloc]init];
        view.backgroundColor = kGreenColor;
        [self addSubview:view];
        view.frame = CGRectMake(0, 8*ADAPTER_WIDTH, 44*ADAPTER_WIDTH, 44*ADAPTER_WIDTH);
        view.layer.cornerRadius = 22*ADAPTER_WIDTH;
        view.layer.masksToBounds = YES;
        _bgView = view;
    }
    return _bgView;
}
- (UILabel *)toplab
{
    if (!_toplab) {
        UILabel *lab = [[UILabel alloc]init];
        [self.bgView addSubview:lab];
        lab.font = [UIFont systemFontOfSize:16*ADAPTER_WIDTH weight:UIFontWeightRegular];
        lab.textColor = WhiteColor;
        lab.textAlignment = NSTextAlignmentCenter;
        lab.numberOfLines = 1;
        [lab mas_makeConstraints:^(MASConstraintMaker *make) {
            make.top.mas_equalTo(3*ADAPTER_WIDTH);
            make.centerX.mas_equalTo(0);
            make.size.mas_equalTo(CGSizeMake(44*ADAPTER_WIDTH, 22*ADAPTER_WIDTH));
        }];
        _toplab = lab;
    }
    return _toplab;
}
- (UILabel *)bottomLab
{
    if (!_bottomLab) {
        UILabel *lab = [[UILabel alloc]init];
        [self.bgView addSubview:lab];
        lab.font = [UIFont systemFontOfSize:11*ADAPTER_WIDTH weight:UIFontWeightRegular];
        lab.textColor = WhiteColor;
        lab.textAlignment = NSTextAlignmentCenter;
        lab.numberOfLines = 1;
        [lab mas_makeConstraints:^(MASConstraintMaker *make) {
            make.bottom.mas_equalTo(-6*ADAPTER_WIDTH);
            make.centerX.mas_equalTo(0);
            make.size.mas_equalTo(CGSizeMake(44*ADAPTER_WIDTH, 16*ADAPTER_WIDTH));
        }];
        _bottomLab = lab;
    }
    return _bottomLab;
}
- (UIImageView *)jiIV
{
    if (!_jiIV) {
        UIImageView *iv = [[UIImageView alloc]init];
        [self addSubview:iv];
        iv.image = [UIImage getPNGimageInBundleWithName:@"ScheduleManager_ji"];
        iv.frame = CGRectMake(self.bgView.right - 12*ADAPTER_WIDTH, 5*ADAPTER_WIDTH, 16*ADAPTER_WIDTH, 15*ADAPTER_WIDTH);
        _jiIV = iv;
    }
    return _jiIV;
}
- (UIImageView *)collectionIV
{
    if (!_collectionIV) {
        UIImageView *iv = [[UIImageView alloc]init];
        [self addSubview:iv];
        iv.image = [UIImage imageNamed:@"ScheduleManager_collection_sure"];
        iv.frame = CGRectMake(self.bgView.right - 12*ADAPTER_WIDTH, 5*ADAPTER_WIDTH, 17*ADAPTER_WIDTH, 17*ADAPTER_WIDTH);
        _collectionIV = iv;
    }
    return _collectionIV;
}
@end
